package com.example.klaraservice.service.impl;

import com.example.klaraservice.dao.CartMapper;
import com.example.klaraservice.pojo.Cart;
import com.example.klaraservice.service.CartService;
import com.example.klaraservice.utils.UrlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : Glacialerisa
 * @date : 2023/6/10 13:35
 * @desc :
 */
@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;
    @Override
    public List<Cart> getCarts(int id) {
        List<Cart> carts = cartMapper.selectCartByUserId(id);
        for (Cart cart:carts){
            String image = cart.getCommodity().getImage();
            cart.getCommodity().setImage(UrlUtil.IP+image);
        }
        return carts;
    }

    @Override
    public Cart getCart(int id) {
        Cart cart = cartMapper.selectCartById(id);
        String image = cart.getCommodity().getImage();
        cart.getCommodity().setImage(UrlUtil.IP+image);
        return cart;
    }

    @Override
    public boolean updateCart(Cart cart) {
        return cartMapper.updateCart(cart);
    }

    @Override
    public boolean deleteCartById(int id) {
        return cartMapper.deleteCartById(id);
    }
}
